 
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "pool.c"
#include "pool.h"
#include <pthread.h>

void *do_task(void *arg)
{
    int * task = (int *)arg;
    printf("task %d\n", *task);
    printf("begin to sleep for 1 sec\n");
    sleep(1);
    return NULL;
}
 
int main(int arg, char **argv)
{
    if (tpool_create(5) != 0)//创建成功之后返回的值是0
    {
        printf("tpool_create failed\n");
        exit(1);
    } else {
        printf("tpool_create successed\n");
    }
 

    for (int i = 0; i < 5; i++)
    {
        tpool_add_work(do_task, (void *)(long)i);
    }
    printf("begin to sleep for 2 sec!\n");
    sleep(2);
   	//摧毁线程池前，主线程会等待子线程们执行routine任务函数，routine里将会执行每一个任务的dotask函数 
    tpool_destroy();
    return 0;
}



